package cn.cy.service.impl;

import cn.cy.dao.BizClaimVoucherDao;
import cn.cy.pojo.BizClaimVoucher;
import cn.cy.pojo.ClaimVoicherCondition;
import cn.cy.service.BizClaimVoucherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("claimVoucherService")
public class BizClaimVoucherServiceImpl implements BizClaimVoucherService {
    @Autowired
    private BizClaimVoucherDao claimVoucherDao;

    @Override
    public List<BizClaimVoucher> findAll() {
        return claimVoucherDao.findAll();
    }

    @Override
    public List<String> findStatusAll() {
        return claimVoucherDao.findStatusAll();
    }

    @Override
    public BizClaimVoucher finfById(Long id) {
        return claimVoucherDao.findById(id);
    }

    @Override
    public Long count() {
        return claimVoucherDao.count();
    }

    @Override
    public List<BizClaimVoucher> finddByStatusAndDate(ClaimVoicherCondition claimVoicherCondition) {
        //是否查状态
        StringBuffer sb = new StringBuffer("from BizClaimVoucher where 1=1 ");
        if(claimVoicherCondition == null){
            claimVoicherCondition = new ClaimVoicherCondition();
            claimVoicherCondition.setTotalCount(count());
            return claimVoucherDao.findSatausAnndDate(sb.toString(),claimVoicherCondition);
        }
        if(claimVoicherCondition.getStatus() != null && !claimVoicherCondition.getStatus().equals("")){
            sb.append(" and STATUS=:STATUS ");
            //是否查起始结束时间段
        }else if(claimVoicherCondition.getStart() != null && !claimVoicherCondition.getStart().equals("") &&
                claimVoicherCondition.getEnd() != null && !claimVoicherCondition.getEnd().equals("") ){
            sb.append("and to_char(createTime,'yyyy-mm-dd') between :status and :end");
            //sb.append(" and CREATE_TIME>:status and CREATE_TIME>:end ");
            //是否查某时间段后
        }else if(claimVoicherCondition.getStart() != null && !claimVoicherCondition.getStart().equals("") &&
                claimVoicherCondition.getEnd() == null  ){
            sb.append(" and to_char(createTime,'yyyy-mm-dd') >:status ");
            //是否查某时间段前
        }else if(claimVoicherCondition.getStart() == null &&
                claimVoicherCondition.getEnd() != null && !claimVoicherCondition.getEnd().equals("") ){
            sb.append(" and to_char(createTime,'yyyy-mm-dd') <:end ");
        }
        return claimVoucherDao.findSatausAnndDate(sb.toString(),claimVoicherCondition);
    }

    @Override
    public void save(BizClaimVoucher claimVoucher) {
        claimVoucherDao.save(claimVoucher);
    }

    @Override
    public void update(BizClaimVoucher claimVoucher) {
        claimVoucherDao.update(claimVoucher);
    }

    @Override
    public void delete(BizClaimVoucher claimVoucher) {
        claimVoucherDao.delete(claimVoucher);
    }






    public BizClaimVoucherDao getClaimVoucherDao() {
        return claimVoucherDao;
    }

    public void setClaimVoucherDao(BizClaimVoucherDao claimVoucherDao) {
        this.claimVoucherDao = claimVoucherDao;
    }
}
